import blog_craw
import threading
import time

def single_thread():
    print ("single_thread begin!")
    for url in blog_craw.urls:
        blog_craw.craw(url)
    print ("single_thread end!")

def multi_thread():
    print("multi_thread begin!")
    threads = []
    for url in blog_craw.urls:
        threads.append(
            threading.Thread(target=blog_craw.craw,args=(url,))
        )

    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()

    print("multi_thread end!")

if __name__ =="__main__":
    start = time.time()
    single_thread()
    end = time.time()
    time1 = end - start
    print ("single thread cost:",time1,"seconds")


    start2 = time.time()
    multi_thread()
    end2 = time.time()
    time2 = end2 - start2
    print ("multi thread cost:",time2,"seconds")

    print("多线程比单线程在爬取50个页面的源码长度上，快了",time1/time2,"倍")